Skip to content

fix: prevent TypeError in PreparedStatement.execute() when streaming without callback#1849

Open
dhensby wants to merge 1 commit intotediousjs:masterfrom
dhensby:fix/ps-execute-stream
Open

fix: prevent TypeError in PreparedStatement.execute() when streaming without callback#1849
dhensby wants to merge 1 commit intotediousjs:masterfrom
dhensby:fix/ps-execute-stream

Conversation

@dhensby
Copy link
Copy Markdown
Collaborator

@dhensby dhensby commented Apr 24, 2026

Summary

Fixes a TypeError: callback is not a function that occurs when calling ps.execute(values) with ps.stream = true and no callback provided.

Root Cause

In _execute(), the inner req.execute('sp_execute', callback) unconditionally calls callback(null, result) on completion — but when streaming without a callback, callback is undefined.

Fix

Guard the callback parameter in _execute() so a no-op function is used when no callback is provided. This allows stream consumers to receive results via row/error/done events on the returned Request object, consistent with how Request.query(), Request.batch(), and Request.execute() handle streaming.

Test

Added a unit test that verifies ps.execute({}) does not throw when stream = true and no callback is given. The test confirms the TypeError regression on master and passes with the fix.

Closes #1848

…without callback

When stream=true and no callback is provided, _execute() would call
callback(null, result) on the undefined callback, throwing TypeError.

Guard the callback in _execute() so a no-op is used when no callback
is provided, allowing stream consumers to receive results via events
on the returned Request object.

Closes tediousjs#1848

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PreparedStatement.execute() throws TypeError when stream=true and no callback provided

1 participant